// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// import qwebchannel from './qt5.15webchannel.js'
import Vue from 'vue'
import App from './App'
import router from './router'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import store from './store/index';
import '../static/css/customer.css'

// 导入 qwebchannel.js
import qwebchannel from './qt5.15webchannel.js';

Vue.config.productionTip = false

var qtCall = null;
if (process.env.NODE_ENV === 'production') {
  new qwebchannel.QWebChannel(qt.webChannelTransport, (channel) => {
    qtCall = channel.objects.webBridge;
    console.log(qtCall)
    qtCall.QtToJs.connect((func, json) => {
      // console.log("收到qt的消息:", jsonStr);////可以接收到qt发送的数据
      if(func=='RefreshSystemAlarmStatus'){
        const datas = JSON.parse(json)
        if (datas.code === 200) {
          console.log('RefreshSystemAlarmStatus返回', datas.data)
          var alarm = datas.data['alarm']
          var alarm_status = alarm['status']
          if(alarm_status==0){
            document.getElementById('showMaskAlarm').style.display = 'block'
          }
          if(alarm_status==1){
            document.getElementById('showMaskAlarm').style.display = 'none'
          }

        }

      }
    });
    qtCall.JsToQt("func", "111");//可以传给qt
    Vue.prototype.$qtCall = qtCall
  });
}else{
  setTimeout(() => {
    console.log('app.init')
  }, 3000);
}
// export var qtHandle = {};
// var data = {
//   totalData: {//数据
//     dt: 3.3,//dt时间
//     ct: 3.3,//ct时间
//     countAll: 32,//总数
//     countOk: 30,//ok数
//     countNg: 2,//ng数
//     rateAll: 90,//总良率
//     rateWg: 30,//外观良率
//     rateFl: 30		//辅料良率
//   },
//   totalRate: {//总良率
//     acupoint1: 80,//工位1良率
//     acupoint2: 80,//工位2良率
//     acupoint3: 80	//工位3良率
//   },
//   wgRate: {//外观良率
//     acupoint1: 80,//工位*良率
//     acupoint2: 80,
//     acupoint3: 80
//   },
//   flRate: {//辅料良率
//     acupoint1: 80,//工位*良率
//     acupoint2: 80,
//     acupoint3: 80
//   },
//   realData: [//实时样本数据
//     {
//       qrcode: "02353CCB++82402061A4001553320242181190450",//条码
//       datetime: "2024-06-18 12:00:00",//测试时间
//       acupoint: "1",//穴位号，界面已移除？
//       rlt: "OK",//结果
//       wg: "压伤",//外观缺陷
//       fl: "背胶膜缺失"	//辅料缺陷
//     },
//     {
//       qrcode: "02353CCB++82402061A4001553320242181190450",
//       datetime: "2024-06-18 12:00:00",
//       acupoint: "1",
//       rlt: "NG",//结果
//       wg: "压伤",//外观缺陷
//       fl: "背胶膜缺失"	//辅料缺陷
//     }
//   ]
// }
// if (process.env.NODE_ENV === 'production') {
//   new qwebchannel.QWebChannel(qt.webChannelTransport, (channel) => {
//     qtCall = channel.objects.webBridge;
//     console.log(qtCall)
//     qtCall.RefreshRealData.connect((jsonStr) => {
//       console.log("收到qt的消息:", jsonStr);////可以接收到qt发送的数据
//     });
//     qtCall.JsToQt("func", "111");//可以传给qt
//     Vue.prototype.qtCall = qtCall
//   });
// } else {
//   var qtCalls = {
//     data: 1,
//     RefreshRealData() {
//       return data
//     }
//   }
//   Vue.prototype.qtCall = qtCalls
// }
import VueLogger from 'vuejs-logger';

// Logger配置
const isProduction = process.env.NODE_ENV === 'production';
const options = {
  isEnabled: true,
  logLevel: isProduction ? 'error' : 'debug',
  stringifyArguments: false,
  showLogLevel: true,
  showMethodName: true,
  separator: '|',
  showConsoleColors: true
};

Vue.use(VueLogger, options);
Vue.use(ElementUI);


Vue.directive('selfdbclick', {
  // 当绑定元素插入到DOM中时
  inserted: function (el) {
    // var inputs = document.getElementsByName('el-datetime')
    // for (let index = 0; index < inputs.length; index++) {
    let element = el.children[0] //inputs[0];
    console.log(element)
    element.addEventListener('dblclick', function(event) {
      console.log('dbclick', 'input-date')
      let start = element.selectionStart
      let end = element.selectionEnd
      if((end - start)!=4){
        end = start+2
      }
      element.setSelectionRange(start, end);
    });
    // }
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})

